package reflect;

import reflect.annotations.AutoRunClass;

import java.io.File;
import java.net.URISyntaxException;

/**
 * 输出与当前类Test4在同一个包中所有类是否被@AutoRunClass标注
 */
public class Test4 {

    public static void main(String[] args) throws URISyntaxException, ClassNotFoundException {
        File dir=new File(Test4.class.getResource(".").toURI());
        String packname = Test4.class.getPackage().getName();
        System.out.println(packname);
        File[] subs=dir.listFiles(f ->f.getName().endsWith(".class"));
        for(File sub:subs){
            String fileName = sub.getName();
            String className = fileName.substring(0,fileName.indexOf("."));
            Class cls=Class.forName(packname+"."+className);
            boolean tf=cls.isAnnotationPresent(AutoRunClass.class);
            if(tf) {
                System.out.println(packname + "." + className + ":被标注了:" + tf);
            }
            else{
                System.out.println(packname+"."+className+":没有被标注："+tf);
            }
        }
    }
}
